﻿using AutoMapper;
using MediatR;
using SheepStorage.API.Application.Command.SheepDeathCommand;
using SheepStorage.API.Application.Command.SheepMarkCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.DataImp;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.SheepDeathHandler
{
    public class SheepDeathAddCommandHandler : IRequestHandler<SheepDeathAddCommand, Results<int>>
    {
        private readonly ISheepDeathService _sheepDeathService;
        private readonly IMapper _mapper;

        public SheepDeathAddCommandHandler(ISheepDeathService sheepDeathService, IMapper mapper)
        {
            _sheepDeathService = sheepDeathService;
            _mapper = mapper;
        }
        /// <summary>
        /// 戴标添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<int>> Handle(SheepDeathAddCommand request, CancellationToken cancellationToken)
        {
            var result=_mapper.Map<SheepDeath>(request);
            return Results<int>.DataResult( await _sheepDeathService.AddSheepDeaths(result));
        }

    }
}
